package com.edge.pbx.utils;

import android.text.TextUtils;

import java.util.Arrays;

public class StringUtils {

    public static void stringToIntArray(String text, int[] array){
        if (array == null || array.length == 0)return;
        int[] tmp = stringToIntArray(text);
        for(int i =0, len = Math.min(array.length, tmp.length); i < len; i++){
            array[i] = tmp[i];
        }
    }

    public static int objectStringToInt(Object tag, int def){
        if (tag == null)return def;
        try {
            return Integer.parseInt(tag.toString());
        } catch (Exception e) {

        }
        return def;
    }

    public static int[]  stringToIntArray(String text){
        if (text == null || text.length() == 0)
            return null;
        String[] temp = text.replace("[", "").replace("]", "").split(",");
        if (temp == null || temp.length == 0)return null;
        int[] array = new int[temp.length];
        try {
            int i = 0;
            for (String s : temp) {
                array[i++] = Integer.parseInt(s.trim());
            }
            return array;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
